package com.junwell.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.junwell.entity.Car;
import com.junwell.mapper.CarMapper;
import com.junwell.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 */
@Service
public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements CarService {

    @Autowired
    private CarMapper carMapper;

    @Transactional
    @Override
    public boolean add(Car car) {
        int i = carMapper.insert(car);
        return  i>0? true:false;
    }

    @Transactional
    @Override
    public Car viewOne(Integer id) {
        QueryWrapper<Car> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);
        Car car = carMapper.selectOne(queryWrapper);
        return  car;
    }

    @Transactional
    @Override
    public boolean update(Car car) {
        int i = carMapper.updateById(car);
        return i>0? true:false;
    }

    @Transactional
    @Override
    public boolean delete(Integer id) {
        QueryWrapper<Car> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);
        int i = carMapper.delete(queryWrapper);
        return i>0? true:false;
    }


}
